import { defineStore } from "pinia"
import { useAppStore } from "./app"

export const useUserStore = defineStore({
  id:'user',
  state:() =>{
    return {
      name:'pzy',
      age:32
    }
  },
  getters:{
    fullName:(state) =>{
      return state.name + '小燕子'
    }
  },
  actions: {
    updateState(data: any){
      this.$state = data;
    },
    updateAppConfig(){
      const appStore = useAppStore() //定义对象
      appStore.setData('app-update') //app.ts中定义的setData()
    }
  },
  //开启数据缓存
  persist:{
    key:'user',
    storage:window.localStorage,
    paths:['name'],
    overwrite:true
  }
})